"""

    使用aiohttp发出web请求

"""
import asyncio
import aiohttp


async def fetch_status(session, url):
    # 超时时间设置，总超时时间为0.1s
    ten_millis = aiohttp.ClientTimeout(total=0.1)
    async with session.get(url, timeout=ten_millis) as result:
        return result.status


async def main():
    # 客户端连接 - 总超时时间为1s，连接超时时间为100毫秒
    session_timeout = aiohttp.ClientTimeout(total=1, connect=.1)
    async with aiohttp.ClientSession(timeout=session_timeout) as session:
        url = "http://www.baidu.com"
        status = await fetch_status(session, url)
        print(f"{url}的状态为{status}")


asyncio.run(main())
